//
//  IMessageRecipientParser.m
//  imessagesender
//
//  Created by Pang lei on 13-7-25.
//  Copyright (c) 2013年 Pang lei. All rights reserved.
//

#import "IMessageRecipientParser.h"
#import "GDataXMLNode.h"
#import "IMessageRecpient.h"

@implementation IMessageRecipientParser

+ (NSMutableArray *)parse:(NSString *)xmlPath
{
    NSMutableArray *array = [[NSMutableArray alloc] init];
    
    GDataXMLDocument *doc = [self loadGDataXMLDocument:xmlPath];
    NSArray *recipientElmenents = [doc.rootElement nodesForXPath:@"//recipients/recipient" error:nil];
    
    for(GDataXMLElement *recipientElement in recipientElmenents) {
        GDataXMLNode *data = [recipientElement attributeForName:@"address"];
        IMessageRecpient *recipient = [[IMessageRecpient alloc] initWithAddress:[data stringValue]];
        [array addObject:recipient];
    }
    
    return array;
}

+ (GDataXMLDocument *)loadGDataXMLDocument:(NSString *)xmlPath
{
    NSData *xmlData = [NSMutableData dataWithContentsOfFile:xmlPath];
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:NULL];
    return doc;
}



@end
